#include "slepbase.h"
#include "epph.h"

#include <assert.h>
#include <math.h>


/*
void fusedLeastR(slep_matrix *A, slep_vector *y, double lambda, OPTS *opts,
				 slep_matrix* x, slep_vector *funVal, slep_vector *ValueL){

	slep_vector *ATy, *b1, *Ax, *x1;
	double rsL2, lambda, lambda_max;
	int i;

	assert( y->dim == A->m);
	assert( lambda >= 0.0);

	sll_opts(opts);
	initNormalization(A,opts);

	//assert( !(A->sparsity==SlepDense && opts->nFlag!=0) );

	Ax = slepAllocDenseVector(A->m);
	ATy = slepAllocDenseVector(A->n);
	b1 = slepAllocDenseVector(y->dim);

	NORMALIZEDMTV(A,y,ATy,opts,b1);

	if( opts->rFlag ==  0){
		if(! hasGot(opts,SlepOPT_fusedPenalty))
			lambda2 = 0.0;
		else
			lambda2 = opts->fusedPenalty;
	}else{
		assert( z >= 0.0 && z <= 1.0);
		lambda_max = slep_damax(ATy);
		lambda = lambda * lambda_max;
		if(! hasGot(opts,SlepOPT_fusedPenalty))
			lambda2 = 0.0;
		else
			lambda2 = opts->fusedPenalty;
	}

	if( opts->init ==  2)
		slep_zerov(x);
	else{
		if(hasGot(opts,SlepOPT_x0)){
			assert(opts->x0->dim == A->n);
			slep_dvcopy(opts->x0,x);
		}else
			slep_dvcopy(ATy, x);
	}

	Ax = slepAllocDenseVector(A->m);
	x1 = slepAllocDenseVector(x->dim);

	NORMALIZEDMV(A,x,Ax,opts,x1,i);

	if( opts->init== 0){
		double x_norm, x_2norm;
		x_norm = slep_dasum(x);
		x_2norm = slep_ddot(x,x);
		if( x_norm >= 1e-6){
			;
		}
	}

	if( ! hasGot(opts,SlepOPT_rStartNum))
		opts->rStartNum = opts->maxIter;
	else{
		if( opts->rStartNum <= 0)
			opts->rStartNum = opts->maxIter;
	}

	if( opts->lFlag == 0){
		double L, alpha, alphap;
		int bFlag;
		slep_vector* z0, *xp, *Axp, *s, *v, *g, *ATAs, *As, *Av, *Axy, *xxp;

		L=1.0;
		bFlag=0;

		xp = slepCopyToNewVector(x);
		Axp = slepCopyToNewVector(Ax);

		s = slepAllocDenseVector(x->dim);
		v = slepAllocDenseVector(x->dim);
		g = slepAllocDenseVector(x->dim);
		ATAs = slepAllocDenseVector(x->dim);
		As = slepAllocDenseVector(A->m);
		Av = slepAllocDenseVector(A->m);
		Axy = slepAllocDenseVector(A->m);

		xxp = slepAllocDenseVector(x->dim);
		slep_zerov(xxp);

		alphap=0.;
		alpha=1.;

		for( iterStep=0; iterStep < opts->maxIter; iterStep++){
	
			beta = (alphap-1.0)/alpha;

			slep_dvcopy(x,s);
			slep_daxpy(beta,xxp,s);

			slep_dvcopy(Ax,As);
			slep_daxpby(-beta, Axp, 1.0+beta, As);

			NORMALIZEDMTV(A,As, ATAs, opts, b1);
			slep_dvcopy(ATAs,g);
			slep_daxpy(-1.0,ATy,g);

			slep_dvcopy(x,xp);
			slep_dvcopy(Ax,Axp);

			for(;;){
				slep_dvcopy(s,v);
				slep_daxpy(-1.0/L,g,v);


				
			}
		}

	}

}

*/